package nettyperformance;

import java.util.concurrent.atomic.AtomicInteger;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;

public class nettyserver {
	private static AtomicInteger count = new AtomicInteger(0);
	public static void main(String args[]){
		NioEventLoopGroup bossGroup =  new NioEventLoopGroup();
		NioEventLoopGroup workerGroup= new NioEventLoopGroup();
		ServerBootstrap bootstrap = new ServerBootstrap();
		bootstrap.group(bossGroup, workerGroup);

		bootstrap.channel( NioServerSocketChannel.class);

		bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
		    @Override protected void initChannel(SocketChannel ch) throws Exception {
		        ChannelPipeline pipeline = ch.pipeline();
		        //todo: add handler
		        count.getAndIncrement();
		        System.out.println("connection num : " + count.get());
		        Thread.sleep(10);
		    }});
		try {
			bootstrap.bind(8080).sync();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
